package core.network.client2game.handler.tdk;

import business.global.pk.tdk.TDKRoom;
import business.global.pk.tdk.TDKdefine;
import business.global.room.RoomMgr;
import business.player.Player;
import business.tdk.c2s.iclass.CTDK_OpCard;
import com.ddm.server.websocket.def.ErrorCode;
import com.ddm.server.websocket.handler.requset.WebSocketRequest;
import com.google.gson.Gson;
import core.network.client2game.handler.PlayerHandler;

import java.io.IOException;

/**
 * 吹牛打牌
 *
 * @author Huaxing
 */
public class CTDKOpCard extends PlayerHandler {
    @SuppressWarnings("rawtypes")
    @Override
    public void handle(Player player, WebSocketRequest request, String message) throws IOException {
        final CTDK_OpCard req = new Gson().fromJson(message, CTDK_OpCard.class);
        long roomID = req.roomID;
        TDKdefine.TDK_OP opType = TDKdefine.TDK_OP.valueOf(req.opType);
        if (TDKdefine.TDK_OP.Not.equals(opType)) {
            request.error(ErrorCode.NotAllow, "CTDKOpCard not find Not opType :" + req.opType);
            return;
        }
        TDKRoom room = (TDKRoom) RoomMgr.getInstance().getRoom(roomID);
        if (null == room) {
            request.error(ErrorCode.NotAllow, "CTDKOpCard not find room:" + roomID);
            return;
        }
        room.opCard(request, player.getId(), req.setID, req.roundID, opType, req.value);
    }
}
